// $(function() {
// 	$("#submit").click(function(){
// 		alert("添加完毕")
// 		history.back();
// 	})
// })

var app = new Vue({
	el: "#main-content",
	data:{
		oldMan: {},
		oldManId:{},
		username:{},
		a_CasesPhotos:"",
		casedetails:null

	},
	mounted: function () {
		this.getOldManData();
	},
	methods: {
		getOldManData:function () {
			let oldManId = getQueryVariable("oldManId");
			// alert(oldManId);
			getOldManData(oldManId);
		},
		caseAdd:function () {
			caseAdd();
		},
		getFile(e){
			let file = e.target.files;
			this.a_CasesPhotos = file[0];
		}
	}
});


//老人基本信息
function getOldManData(oldManId) {
	let data=new URLSearchParams();
	data.append("oldManId",oldManId);
	axios({
		method: 'post',
		url: "nurse/oldmandata",
		data:data
	}).then((ins) => {
		console.log(ins.data);
		let nhDto = ins.data;
		let oldMan = nhDto.data;
		if (nhDto.code == 200) {
			app.oldMan = oldMan;
			app.oldManId = oldMan.id;
			app.username = oldMan.username;
		} else if (nhDto.code == 500) {
			location.href = "/500.html";
		}
	})
};


function caseAdd() {
	let data=new FormData();
	data.append("oldmanid",app.oldManId);
	data.append("a_CasesPhotos",app.a_CasesPhotos);
	data.append("casedetails",app.casedetails);
	axios({
		method: 'post',
		url: "nurse/caseadd",
		data: data
	}).then((ins) => {
		console.log(ins.data);
		let nhDto = ins.data;
		let oldMan = nhDto.data;
		if (nhDto.code == 200) {
			history.back();
		} else if (nhDto.code == 500) {
			location.href = "/500.html";
		}
	})

}

//获取地址栏参数
function getQueryVariable(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if(pair[0] == variable){return pair[1];}
	}
	return(false);
}